package com.hao.study.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hao.study.entity.Comment;
import com.hao.study.service.CommentService;
import com.hao.study.mapper.CommentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Administrator
* @description 针对表【b_comment】的数据库操作Service实现
* @createDate 2024-06-12 13:46:44
*/
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment>
    implements CommentService{
    @Autowired
    CommentMapper mapper;

    @Override
    public PageInfo<Comment> getCommentList(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Comment> list = mapper.getList();
        return PageInfo.of(list);
    }

    @Override
    public void createComment(Comment comment) {
        comment.setCommentTime(String.valueOf(System.currentTimeMillis()));
        mapper.insert(comment);
    }

    @Override
    public void deleteComment(String id) {
        mapper.deleteById(id);
    }

    @Override
    public void updateComment(Comment comment) {
        mapper.updateById(comment);
    }

    @Override
    public Comment getCommentDetail(String id) {
        System.out.println(id);
        return mapper.selectById(id);
    }

    @Override
    public PageInfo<Comment> getThingCommentList(Integer pageNum, Integer pageSize, String thingId, String order) {
        PageHelper.startPage(pageNum,pageSize);
        List<Comment> list = mapper.selectThingCommentList(thingId, order);
        return PageInfo.of(list);
    }

    @Override
    public PageInfo<Comment> getUserCommentList(Integer pageNum, Integer pageSize, String userId) {
        PageHelper.startPage(pageNum,pageSize);
        List<Comment> list = mapper.selectUserCommentList(userId);
        return PageInfo.of(list);
    }
}




